// Copyright 2022 a.o.smith ALL Rights Reserved
package com.liuxinlong.modules.butler.controller;

import com.liuxinlong.annotation.LogAnnotation;
import com.liuxinlong.constant.LogBusinessConstants;
import com.liuxinlong.constant.LogOperateConstants;
import com.liuxinlong.modules.butler.controller.request.QueryCommentReq;
import com.liuxinlong.modules.butler.controller.request.UpdateLecturerReq;
import com.liuxinlong.modules.butler.service.LecturerService;
import com.liuxinlong.modules.common.controller.request.BaseDeleteReq;
import com.liuxinlong.modules.common.controller.response.BaseResp;
import com.liuxinlong.modules.entity.Lecturer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 讲师管理控制层
 *
 * @author liuxinlong@hotwater.com.cn
 * @version 1.0.0
 * @since 2022-12-08
 */
@RestController
@RequestMapping("/butler/lecturer")
public class LecturerController {

    @Autowired
    private LecturerService lecturerService;

    /**
     * 分页查询讲师信息
     *
     * @param req 请求信息
     * @return 讲师信息列表
     */
    @PostMapping("page")
    public BaseResp pageFaqInfo(@RequestBody QueryCommentReq req) {
        Map<String, Object> queryMap = new HashMap<>();
        queryMap.put("startNum", req.getStartNum());
        queryMap.put("pageSize", req.getPageSize());
        queryMap.put("keyword", req.getKeyword());
        List<Map<String, Object>> dataList = lecturerService.pageLecturerInfo(queryMap);
        int totalNum = lecturerService.getLecturerInfoCount(queryMap);
        BaseResp resp = new BaseResp();
        resp.setRetMessage("分页查询讲师信息成功");
        resp.setDataList(dataList);
        resp.setTotalNum(totalNum);
        return resp;
    }
    
    /**
     * 新增讲师信息
     *
     * @param req 请求信息
     * @return 成功标识
     */
    @PostMapping("add")
    @LogAnnotation(value = "新增讲师信息", business = LogBusinessConstants.LECTURER_MANAGE, operateType = LogOperateConstants.OPERATE_MODIFY)
    public BaseResp addLecturer(@RequestBody UpdateLecturerReq req) {

        Lecturer lecturer = new Lecturer();
        lecturer.setName(req.getName());
        lecturer.setArea(req.getArea());
        lecturer.setBrief(req.getBrief());
        lecturer.setPicture(req.getPicture());
        lecturerService.addLecturerInfo(lecturer);
        BaseResp resp = new BaseResp();
        resp.setRetMessage("新增讲师信息成功");
        return resp;
    }

    /**
     * 修改讲师信息
     *
     * @param req 请求信息
     * @return 成功标识
     */
    @PostMapping("update")
    @LogAnnotation(value = "修改讲师信息", business = LogBusinessConstants.LECTURER_MANAGE, operateType = LogOperateConstants.OPERATE_MODIFY)
    public BaseResp updateLecturer(@RequestBody UpdateLecturerReq req) {

        Lecturer lecturer = new Lecturer();
        lecturer.setId(req.getId());
        lecturer.setName(req.getName());
        lecturer.setArea(req.getArea());
        lecturer.setBrief(req.getBrief());
        lecturer.setPicture(req.getPicture());
        lecturerService.updateLecturer(lecturer);
        BaseResp resp = new BaseResp();
        resp.setRetMessage("修改讲师信息成功");
        return resp;
    }

    /**
     * 删除讲师信息
     *
     * @param req 请求信息
     * @return 成功标识
     */
    @PostMapping("delete")
    @LogAnnotation(value = "删除讲师信息", business = LogBusinessConstants.LECTURER_MANAGE, operateType = LogOperateConstants.OPERATE_DELETE)
    public BaseResp deleteLecturer(@RequestBody BaseDeleteReq req) {
        lecturerService.deleteLecturer(req.getId());
        BaseResp resp = new BaseResp();
        resp.setRetMessage("删除讲师信息成功");
        return resp;
    }
    
}
